const {connection} = require('./sqlhelper')
module.exports={
    addNewPost(data,callback){
        // console.log(data);
        let sql = `INSERT INTO posts
    SET title='${data.title}',content='${data.content}',slug='${data.slug}',
    feature='${data.feature}',category_id=${data.category},
    created='${data.created}',\`status\`='${data.status}',
    user_id=${data.id}`;
        connection.query(sql, (err, result) => {
            err && console.log(err);
            callback(result);
        })
    },
    getPostById(id,callback){
        let sql = `SELECT * FROM posts WHERE id='${id}'`;
        connection.query(sql,(err,result)=>{
            err&&console.log(err);
            callback(result[0]);
        })
    },
    updatePostById(data,callback){
        let sql = `UPDATE posts
    SET title='${data.title}',content='${data.content}',slug='${data.slug}',
    feature='${data.feature}',category_id=${data.category},
    created='${data.created}',\`status\`='${data.status}',
    user_id=${data.user_id} WHERE id='${data.id}' `;
        connection.query(sql, (err, result) => {
            err && console.log(err);
            callback(result);
        })
    }
}